package JUnitTests;

import java.util.ArrayList;

import mcommand.*;
import junit.framework.TestCase;

/**
 * tests the sort of the highscore.
 * tests the max count of scores in highscore.
 *
 * @author Marcel, Christian, Klaus
 */
public class HighscoreCountTest extends TestCase {

    Highscore hs;
    private final int MAX_HIGHSCORE_COUNT = 10;
    private final int RANDOM_RANGE = 1000;

    /**
     * calls the setUp method of the super class.
     */
    protected final void setUp() throws Exception {
        super.setUp();
    }

    /**
     * filled the testhighscore with ten different scores.
     */
    public final void fillHighscore() {
        for (int durchgang = 0; durchgang < MAX_HIGHSCORE_COUNT; durchgang++) {
            HighscoreUnit hu = new HighscoreUnit("hh" + (durchgang),
                    durchgang);
            hs.addHighscoreTest(hu);
        }
    }

    /**
     * add 10 random scores to the testhighscore.
     */
    public final void addRandomHighscore() {
        for (int i = 0; i < MAX_HIGHSCORE_COUNT; i++) {
            HighscoreUnit hu = new HighscoreUnit("hh",
                    (int) (RANDOM_RANGE * Math.random()));
            hs.addHighscoreTest(hu);
        }
    }

    /**
     * the test method for the sort test. 
     *
     * @return true if test is right, false if test is false.
     */
    public final boolean testBiggerThanPreviouse() {
        ArrayList<HighscoreUnit> hutemp = hs.getHighscore();
        for (int i = 0; i < (MAX_HIGHSCORE_COUNT - 1); i++) {
            if (hutemp.get(i).score < hutemp.get(i + 1).score) {
                return false;
            }
        }

        return true;
    }

    /**
     * test the sort of the highscore.
     */
    public final void testSort() {
        hs = new Highscore(false);
        addRandomHighscore();

        assertEquals(true, testBiggerThanPreviouse());
    }

    /**
     * test the maximum size of the highscore.
     */
    public final void testHighscoreSize() {
        hs = new Highscore(false);
        fillHighscore();

        assertEquals(MAX_HIGHSCORE_COUNT, hs.getHighscore().size());
    }

    /**
     * calls the tearDowne method of the super class.
     */
    protected final void tearDown() throws Exception {
        super.tearDown();
    }

}
